package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.VarietySpecs;
import com.fantastic.service.zjs.VarietySpecsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/31 10:37
 * @description: 菜品信息和菜品规格信息关联表控制器
 */
@RestController
@RequestMapping("varietySpecs")
public class VarietySpecsControllerAdmin {

    @Resource
    private VarietySpecsService varietySpecsService;

    /**
     * 查询
     * 无条件时是查询全部的分页查询
     * 有条件时是查询条件的分页查询
     *
     * @param varietySpecs
     * @return
     */
    @GetMapping("/listVarietySpecs")
    public ResultData listVarietySpecs(VarietySpecs varietySpecs,
                                       @RequestParam(name = "page",
                                               defaultValue = "1") int pageNum,
                                       @RequestParam(name = "limit", defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<VarietySpecs> varietySpecsList = varietySpecsService.listVarietySpecs(varietySpecs);
        PageInfo<VarietySpecs> varietySpecsPageInfo = new PageInfo<>(varietySpecsList);
        return new ResultData(RespStatusInfo.OK, varietySpecsPageInfo);
    }

    /**
     * 查询单个菜品信息和菜品规格信息关联表信息
     * 通过菜品id和菜品规格信息id 查询变动价格
     *
     * @param varietyId 菜品信息id
     * @param specId    菜品规格信息
     * @return
     */
    @GetMapping("/getVarietySpecs")
    public ResultData getVarietySpecs(Integer varietyId, Integer specId) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.getVarietySpecs(varietyId, specId));
    }

    /**
     * 查询全部或是单个菜品信息和多个规格的关联信息
     *
     * @param varietyId 菜品信息id
     * @return
     */
    @GetMapping("/listVarietySpecsVo")
    public ResultData listVarietySpecsVo(Integer varietyId) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.listVarietySpecsVo(varietyId));
    }

    /**
     * 查询所有的菜品规格类型和其类型下的具体规格
     *
     * @return
     */
    @GetMapping("/listSpecsType")
    public ResultData listSpecsType() {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.listSpecsType());
    }

    /**
     * 添加菜品信息和菜品规格信息关联表信息
     *
     * @param varietySpecs
     * @return
     */
    @PostMapping("/insertVarietySpecs")
    public ResultData insertVarietySpecs(VarietySpecs varietySpecs) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.insertVarietySpecs(varietySpecs));
    }

    /**
     * 批量添加菜品信息和菜品规格信息关联表信息
     *
     * @param varietySpecs
     * @return
     */
    @PostMapping("/addsVarietySpecs")
    public ResultData addsVarietySpecs(@RequestBody List<VarietySpecs> varietySpecs) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.addsVarietySpecs(varietySpecs));
    }

    /**
     * 修改菜品信息和菜品规格信息关联表信息
     *
     * @param varietySpecs
     * @return
     */
    @PostMapping("/updateVarietySpecs")
    public ResultData updateVarietySpecs(VarietySpecs varietySpecs) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.updateVarietySpecs(varietySpecs));
    }

    /**
     * 删除菜品信息和菜品规格信息关联表信息
     *
     * @param varietyId
     * @param specId
     * @return
     */
    @PostMapping("/deleteVarietySpecs")
    public ResultData deleteVarietySpecs(Integer varietyId, Integer specId) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.deleteVarietySpecs(varietyId, specId));
    }

    /**
     * 批量删除菜品信息和菜品规格信息关联表信息
     *
     * @param varietyId
     * @param specId
     * @return
     */
    @PostMapping("/deletesVarietySpecs")
    public ResultData deletesVarietySpecs(Integer[] varietyId, Integer[] specId) {
        return new ResultData(RespStatusInfo.OK, varietySpecsService.deletesVarietySpecs(varietyId, specId));
    }

}
